<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import ErpPackageMemberModal from './modules/ErpPackageMemberModal.vue'

export default {
  name: 'ErpPackageMemberList',
  components: { ErpPackageMemberModal },
  mixins: [JeecgListMixin],
  props: {
    groupId: {
      type: String,
      default: '',
      required: false
    },
    groupType: {
      type: String,
      default: '',
      required: false
    }
  },
  watch: {
    groupId: {
      immediate: true,
      handler(val) {
        if (!val) {
          this.clearList()
        } else {
          this.queryParam['groupId'] = val
          this.loadData(1)
        }
      }
    }
  },
  data() {
    return {
      disableMixinCreated: true,
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 40,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '小组成员',
          align: 'center',
          dataIndex: 'member'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 100,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        // list: '/packagegroup/erpPackageGroup/queryErpPackageGroupMemberByMainId',
        list: '/packagegroup/erpPackageGroup/memberList',
        delete: '/packagegroup/erpPackageGroup/deleteMember',
        deleteBatch: '/packagegroup/erpPackageGroup/deleteBatchMember'
      },
      disableMixinCreated: true,
    }
  },
  methods: {
    clearList() {
      this.dataSource = []
      this.selectedRowKeys = []
      this.ipagination.current = 1
    }
  }
}
</script>

<template>
  <div class="cargo-group-member-list-container">
    <!-- 操作按钮区域 -->
    <div class="table-operator" v-if="groupId">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
    </div>
    <!-- table区域-begin -->
    <div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :scroll="{x:true}"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange">
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />
          <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
            <a>删除</a>
          </a-popconfirm>
        </span>
      </a-table>
    </div>
    <erp-package-member-modal ref="modalForm" @ok="modalFormOk" :groupId="groupId" :groupType="groupType"/>
  </div>
</template>

<style scoped>
@import '~@assets/less/common.less';
</style>